package com.sghd.candy.module.fight.manager;

import com.sghd.common.ramcache.anno.Inject;
import com.sghd.common.ramcache.service.EntityCacheService;
import com.sghd.pojo.candy.fight.enums.Grade;
import org.springframework.stereotype.Component;

import java.util.Comparator;
import java.util.List;

/**
 * @author Allen
 * @date 2018/12/18
 */
@Component
public class LevelConfigManager {
    @Inject
    private EntityCacheService<LevelId, LevelConfig> levelConfigCache;

    public LevelConfig getLevelConfig(LevelId levelId) {
        return levelConfigCache.load(levelId);
    }
    public LevelId getNextLevel(LevelConfig levelConfig) {
        List<LevelConfig> list = levelConfigCache.getFinder().sort(Comparator.comparing(LevelConfig::getLevelStr));
        int index = list.indexOf(levelConfig);
        if (index >= list.size() - 1) {
            return LevelId.valueOf(-1,-1);
        } else {
            return list.get(index + 1).getLevelId();
        }
    }

    void configMoney(LevelConfig levelConfig, long money) {
        levelConfig.configMoney(money);
    }

    void configElement(LevelConfig levelConfig, int dropCount) {
        levelConfig.configElement(dropCount);
    }

    void configBoxKey(LevelConfig levelConfig, int boxKeyId, float dropRate) {
        levelConfig.configBoxKey(boxKeyId, dropRate);
    }

    void configGrade(LevelConfig levelConfig, Grade grade, String key, Integer value) {
        switch (grade) {
            case ONE:
                levelConfig.configGradeOne(key, value);
                break;
            case TWO:
                levelConfig.configGradeTwo(key, value);
                break;
            case THREE:
                levelConfig.configGradeThree(key, value);
                break;
            default:

        }
    }
}
